<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- import common templates -->
<xsl:import href="../xml/templates/common.xsl"/>
<!-- import signup templates -->
<xsl:import href="../xml/templates/nav.xsl"/>
<!-- import main_app templates -->
<xsl:import href="../xml/templates/nav_app.xsl"/>
<!-- xsl output -->
<xsl:output method='html' encoding='UTF-8' doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" indent='yes'/>

	<!-- template to generate main content -->
	<xsl:template name="FeedscribeContent">
		<!-- load extra tabindex params -->
		<xsl:call-template name="ExtraDataLoader">
			<xsl:with-param name="src" select="extradata/tabindex"/>
		</xsl:call-template>
		<!-- main tab page -->
		<div id="tab_wrapper">
			<!-- checkurl if not subscribe or submit_err page -->
			<form method="post" id="subs_form" action="../cgi-bin/checkurl.pl">
				<!-- subscribe feed if success page / error on submit -->
				<xsl:if test="input/subscribe">
					<xsl:attribute name="action">../cgi-bin/feedscribe.pl</xsl:attribute>
				</xsl:if>
				
				<!-- main page -->
				<h1>Subscribe to RSS feeds</h1>

				<fieldset><legend>Automatic RSS Checker</legend>
					<a href="../help/walkthrough.html#arg_add" onclick="return false;" rel="You can register a new RSS Subscription by putting a URL (a link to a web page or a direct link to an RSS feed). Then you have to check if the URL you inserted have been correctly parsed, in that case you have to select a specific type of RSS (if more than one) and insert a name for your new feed."><img class="help_ico" id="checker_help" src="../images/icons/help.png" alt="help"  /></a>
					<xsl:if test="not(input/subscribe) and not(input/submit)">
						
					</xsl:if>
					<!-- if not on success page -->
					<xsl:if test="not(input/subscribe) and not(input/submit)">
						<label for="http_input">Put here the URL of the page with some RSS feeds or a direct link to a feed</label>
						<!--  basic URL input -->
						<input id="http_input" name="url" type="text" value="http://">
							<xsl:if test = "input/url">
								<xsl:attribute name="value"><xsl:value-of select="input/url"/></xsl:attribute>
							</xsl:if>
						</input>
						<!-- hidden id value -->
						<input id="id" name="id" type="hidden"><xsl:attribute name="value">
							<!-- idpath on error tag -->
							<xsl:value-of select="input/id"/>
						</xsl:attribute></input>
						<!-- hidden step2 value -->
						<input name="step" type="hidden"><xsl:attribute name="value">
							<!-- step value on error tag -->
							<xsl:value-of select="input/step"/>
						</xsl:attribute></input>
						<input value="Check RSS!" type="submit" id="RSSCheckButton" onclick="CheckRSSUrl.check(document.getElementById('http_input').value); return false;" />
					</xsl:if>
					<!-- errors -->
					<xsl:if test='input/err_type and input/checkurl'>
						<p id="error" class="error"><xsl:if test="not(input/feed_name)">The URL you specified does not exist or is unreachable!<br/></xsl:if>
						Error type: <xsl:copy-of select="input/err_type"/></p>
					</xsl:if>
					<!-- feed subscribed (no real error) -->
					<xsl:if test='input/submitted'>
						<p id="subscribed" class="subscribed"> Congratulation, Feed subscribed successfully</p>
					</xsl:if>
					<!-- critical error: typedata not defined -->
					<xsl:if test='error_empty_data'>
						<p id="error" class="error">ERROR NO TYPEDATA SET</p>
					</xsl:if>
					<!-- success page / feed to subscribe (errors may occurr) -->
					<xsl:if test="input/subscribe or input/submit">
						<xsl:if test="not(input/err_type)">
							<p id="des_par"><span>You checked for: </span><xsl:value-of select="input/description"/></p>
								<label for="available_feeds" id="feeds_label">Available feeds: </label><select id="available_feeds" name="link">
								<!-- set feed entries -->
								<xsl:for-each select="input/feedreport">
									<option>
										<!-- feed link -->
										<xsl:attribute name="value"><xsl:value-of select="link"/></xsl:attribute>
										<!-- feed name -->
										<xsl:value-of select="title"/>
									</option>
								</xsl:for-each>
								</select>
						</xsl:if>
						<br/><label for="feed_name">Insert a name for your feed : </label><input id="feed_name" name="feed_name">
						<xsl:attribute name="value"><xsl:value-of select="input/feed_name"/></xsl:attribute></input>
						<!-- group input -->
						<label for="feed_name" id="group_label">Select a group for your new feed : </label>
						<xsl:if test="not(input/step)">
							<select id="group_select" name="group_name">
								<option selected="selected"/>
								<!-- other groups -->
								<xsl:call-template name="GroupsLoader">
									<xsl:with-param name="src" select="$src_data"/>
									<xsl:with-param name="groupname" select="''"/>
								</xsl:call-template>
							</select>
						</xsl:if>
						<!-- hidden id value -->
						<input name="id" type="hidden"><xsl:attribute name="value">
							<!-- idpath on success tag -->
							<xsl:value-of select="input/id"/>
						</xsl:attribute></input><br/>
						<!-- hidden step2 value -->
						<xsl:if test="input/step">
							<input name="step" type="hidden"><xsl:attribute name="value">
								<!-- step value on success tag -->
								<xsl:value-of select="input/step"/>
							</xsl:attribute></input>
						</xsl:if>
						<!-- if on success/err_type save feed link -->
						<xsl:if test="input/err_type">
							<input name="link" type="hidden"><xsl:attribute name="value">
								<!-- idpath on success tag -->
								<xsl:value-of select="input/link"/>
							</xsl:attribute></input>
						</xsl:if>
						<input id="sub_button" value="Subscribe!" type="submit"/>
						<!-- errors -->
						<xsl:if test='input/err_type'>
							<p id="error" class="error">An error occurred : <xsl:copy-of select="input/err_type"/></p>
						</xsl:if>
					</xsl:if>
				</fieldset>
			</form>
			<!-- reset button -->
			<xsl:if test="input/subscribe">
				<form id="reset_form" method="get" action="../cgi-bin/addfeed.pl">
				<!-- check if on Sign Up -->
					<xsl:if test="input/step">
						<!-- change action script -->
						<xsl:attribute name="method">post</xsl:attribute>
						<xsl:attribute name="action">../cgi-bin/step2.pl</xsl:attribute>
						<!-- hidden step2 value -->
						<input name="step" type="hidden"><xsl:attribute name="value">
							<!-- step value on error tag -->
							<xsl:value-of select="input/step"/>
						</xsl:attribute></input>
					</xsl:if>
					<input name="id" type="hidden">
						<!-- idpath on success tag -->
						<xsl:attribute name="value">
							<xsl:value-of select="input/id"/>
						</xsl:attribute>
					</input><span>Wrong feeds page? </span>
					<input id="reset_button" value="Abort Subscription!" type="submit" />
				</form>
			</xsl:if>
			 
			 <xsl:if test="not(input/step)">
				<h2>Already subscribed feeds</h2>
				<ul id="subs_group_list">
				<xsl:for-each select="$src_data/userfeed/group">
					
					<li class="alr_group_name"><span><xsl:value-of select="@groupname"/></span>
						<ul>
							<xsl:for-each select="feed">
								<li>
									<h6><xsl:value-of select="name"/></h6>
									<a>
										<xsl:attribute name="href">
											<xsl:value-of select="link"/>
										</xsl:attribute>
										<xsl:value-of select="link"/>
									</a>
								</li>
							</xsl:for-each>
						</ul>
					</li>				
				</xsl:for-each>
				</ul>	
			</xsl:if>
		</div>
	
	</xsl:template>
	
	<!-- CREATE PAGE -->
	
	<!-- create page structure -->
	<xsl:template match="root">
		<html>
			<!-- head -->
			<head>
				<!-- load common code -->
				<xsl:call-template name="Loader">
					<xsl:with-param name="src" select="$src_head"/>
				</xsl:call-template>
				<!-- load extra head params -->
				<xsl:call-template name="ExtraDataLoader">
					<xsl:with-param name="src" select="extradata/head"/>
				</xsl:call-template>
				<!-- load ie fix -->
				<xsl:call-template name="IELoader">
					<xsl:with-param name="src" select="$src_head_ie/root/common"/>
				</xsl:call-template>
				<xsl:call-template name="IELoader">
					<xsl:with-param name="src" select="extradata/IEFix"/>
				</xsl:call-template>
				<!-- pagetitle -->
				<title><xsl:value-of select="pagetitle"/></title>
			</head>
			<body>
				<!-- body onload attribute -->
				<xsl:if test="extradata/body/onload/text() != ''">
					<xsl:attribute name="onLoad"><xsl:value-of select="extradata/body/onload"/></xsl:attribute>
				</xsl:if>
				<!-- header -->			
				<xsl:call-template name="Loader">
					<xsl:with-param name="src" select="$src_header"/>
				</xsl:call-template>
				<!-- navbar -->
				<!-- if signup page or -->
				<xsl:if test="page = 'signup'">
					<div id="navbar">
						<xsl:call-template name="NavLoader">
							<xsl:with-param name="src" select="$src_navbar"/>
						</xsl:call-template>
					</div>
				</xsl:if>
				<!-- if feedscribe page -->
				<xsl:if test="page = 'feedscribe'">
						<xsl:call-template name="ProfileLoader">
							<xsl:with-param name="sid" select="input/id"/>
							<xsl:with-param name="page" select="page"/>
						</xsl:call-template>				
					<div id="main_app_navigation">
						<xsl:call-template name="NavAppLoader">
							<xsl:with-param name="src" select="$src_navbar"/>
						</xsl:call-template>
					</div>
				</xsl:if>
				<!-- content -->
				<xsl:call-template name="FeedscribeContent">
					<!--<xsl:with-param name="src" select="$src_footer"/>-->
				</xsl:call-template>				
				<!-- footer -->
				<xsl:call-template name="Loader">
					<xsl:with-param name="src" select="$src_footer"/>
				</xsl:call-template>				
			</body>
		</html>
	</xsl:template>
	
</xsl:stylesheet>	
